package com.acme.bankapp.service.bank;

import com.acme.bankapp.service.bank.exception.NotEnoughFundsException;
import com.acme.bankapp.service.bank.exception.OverDraftLimitExceededException;
import com.acme.bankapp.test.TestApplication;

public class BankApplication {

	public static final double MAX_BALANCE = 100;
	
	enum TypeOperation {
		DEPOSIT_OF_FUNDS,
		WITHDRAWAL_OF_FUNDS
	}
	
	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		Bank someBank = null;
		for (int i = 0; i < args.length; i++) {
			if (args[i].equals("-loadbank")) {
				someBank = BankService.readBank();
			} else if (args[i].equals("-loadfeed") && i < args.length - 1) {
				String fileName = args[i+1];
				someBank = TestApplication.getTestBank();
				BankDataLoaderService.readFeed(someBank, fileName);
			}
		}
		
		if (someBank == null) {
			someBank = TestApplication.getTestBank();
			TestApplication.fillTestBank(someBank);
		}
		
		BankService.printBalance(someBank);
		BankService.printMaximumAmountToWithdraw(someBank);
	}
	
	public static void modifyBank(Bank bank, int clientId, int accountId, TypeOperation type, double diffBalance) {
		try {
			switch (type) {
			case DEPOSIT_OF_FUNDS:
				bank.getClients()[clientId].getAccounts()[accountId].deposit(diffBalance);
				break;
			case WITHDRAWAL_OF_FUNDS:
				bank.getClients()[clientId].getAccounts()[accountId].withdraw(diffBalance);
			}
		} catch (IllegalArgumentException exception) {
			System.out.println(exception.getMessage());
		} catch (OverDraftLimitExceededException exception) {
			System.out.println(exception.getMessage());
		} catch (NotEnoughFundsException exception) {
			System.out.println(exception.getMessage());
		}
	}
}
